package lab02.test24;

import java.util.*;
import java.text.*;

public class Test24 {
    public static void main(String[] args) throws ParseException {
        SimpleDateFormat time = new SimpleDateFormat("yyyyMMdd");
        Scanner date = new Scanner(System.in);
        System.out.println("请输入两个日期yyyyMMdd，第二个日期大于第一个");
        String date1 = date.next();
        String date2 = date.next();


        Date time1 = time.parse(date1);
        Date time2 = time.parse(date2);

        Calendar ca1 = Calendar.getInstance();
        ca1.setTime(time1);
        Calendar ca2 = Calendar.getInstance();
        ca2.setTime(time2);


        int day1 = ca1.get(Calendar.DAY_OF_YEAR);


        int day2 = ca2.get(Calendar.DAY_OF_YEAR);


        int year1 = ca1.get(Calendar.YEAR);
        int year2 = ca2.get(Calendar.YEAR);

        if (year1 != year2) {
            int daysBetween = 0;
            for (int i = year1; i < year2; i++) {
                if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)    //闰年
                {
                    daysBetween += 366;
                } else    //不是闰年
                {
                    daysBetween += 365;
                }

            }

            daysBetween += (day2 - day1);
            System.out.println(daysBetween);
        } else    //
        {
            System.out.println("判断day2 - day1 : " + (day2 - day1));

        }
    }

}

